/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package session;

import entity.MSpecialist;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;
/**
 *
 * @author Munliga
 */
@Stateless
public class MSpecialistFacade extends AbstractFacade<MSpecialist> {
    @PersistenceContext(unitName = "MedicalHub-warPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public MSpecialistFacade() {
        super(MSpecialist.class);
    }

public List<MSpecialist> LoadDataSpecialist( String txtID, String txtName, String sortIndex, String sortDirection) {
        try {
            String strQuery = "SELECT m FROM MSpecialist m ";
            String strWhere = " Where 1=1 ";
            strWhere += (!txtName.isEmpty()) ? " AND m.ID = " + txtID + " " : " ";
            strWhere += (!txtName.isEmpty()) ? " AND m.name Like '%" + txtName + "%' " : " ";
            strWhere += "ORDER BY m." + sortIndex + " " + sortDirection;
            strQuery += strWhere;
            return em.createQuery(strQuery).getResultList();
        } catch (Exception e) {
            return null;
        }
    }
}
